package SwingView.Gradebook;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jdesktop.swingx.JXDatePicker;

import SwingController.CmsPresenter;
import SwingModel.CmsAssignment;
import SwingModel.CmsGradebook;
import SwingView.CmsContentPanelModel;
import SwingView.CmsTimeSelector;
import javax.swing.border.EmptyBorder;

public class CmsCPInstructorGradebook extends CmsContentPanelModel{

	private final JLabel jlAsgmEditTitle;
	private JTextField jtfTitle;
	private JTextArea jtfDescription;
	private CmsGradebook gradebook;
	private JTable jtbGradebook;
	private JLabel lblModifiedGradesAre;

	
	public CmsCPInstructorGradebook(){
		
		//helper panel to center the title panel
		JPanel jp = new JPanel();
		jp.setPreferredSize(new Dimension(650, 65));
		jp.setOpaque(false);
		jp.setBorder(BorderFactory.createEmptyBorder());
		GridBagLayout gbl_jp = new GridBagLayout();
		jp.setLayout(gbl_jp);
		


		jtbGradebook = new JTable();
		jtbGradebook.setGridColor(Color.LIGHT_GRAY);
		jtbGradebook.setFillsViewportHeight(true);
		jtbGradebook.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		jtbGradebook.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
		
		//Set up the scroll bar
		JScrollPane scroll = new JScrollPane(jtbGradebook);
		
		//main Scroll bar
		scroll.setBorder(BorderFactory.createEmptyBorder());
		scroll.setOpaque(true);
		scroll.setPreferredSize(new Dimension(650,450));
		scroll.setBackground(Color.WHITE);

		//set up main panel and add components
		setLayout(new BorderLayout());
		setOpaque(false);
		add(jp,BorderLayout.NORTH);//Add title People
		
		//instantiate Quiz title
		jlAsgmEditTitle = new JLabel("Gradebook");
		jlAsgmEditTitle.setFont(jlAsgmEditTitle.getFont().deriveFont(20.0f).deriveFont(Font.BOLD));
		jlAsgmEditTitle.setBorder(new EmptyBorder(0, 8, 5, 8));
		GridBagConstraints gbc_jlQuizComposerTitle = new GridBagConstraints();
		gbc_jlQuizComposerTitle.insets = new Insets(0, 0, 5, 0);
		gbc_jlQuizComposerTitle.gridx = 0;
		gbc_jlQuizComposerTitle.gridy = 0;
		jp.add(jlAsgmEditTitle, gbc_jlQuizComposerTitle);
		
		lblModifiedGradesAre = new JLabel("<Modified grades are automatically saved and updated in the database>");
		lblModifiedGradesAre.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		lblModifiedGradesAre.setForeground(new Color(165, 42, 42));
		GridBagConstraints gbc_lblModifiedGradesAre = new GridBagConstraints();
		gbc_lblModifiedGradesAre.anchor = GridBagConstraints.PAGE_START;
		gbc_lblModifiedGradesAre.gridx = 0;
		gbc_lblModifiedGradesAre.gridy = 1;
		jp.add(lblModifiedGradesAre, gbc_lblModifiedGradesAre);
		add(scroll,BorderLayout.WEST);//Add People List
		
		
		
	}
	
	public void loadGradebook(CmsGradebook gradebook){
		this.gradebook = gradebook;
		jtbGradebook.setModel(gradebook);
		jtbGradebook.revalidate();
		jtbGradebook.repaint();
		revalidate();
		repaint();
	}

}
